<?php


namespace App\Log;


use Auth,Saas;

class AdminImgLog extends AdminLog
{
    protected $pre = [];    //修改前
    protected $next = [];   //修改后
    protected $module;      //操作模块

    protected $mean = [
    ];


    public function __construct($pre,$next,$module)
    {
        $this->pre = $pre;
        $this->next = $next;
        $this->module = $module;
    }

    public function addLog()
    {
        $this->data = $this->combinedData();
        parent::addLog();
    }


    public function combinedData():array
    {
        $content = [];
        if (!empty( $this->next)){
            foreach ($this->next as $key => $val){
                if (isset( $this->mean[$key])){
                    if (isset( $this->other[$key])){
                        $meanInfo = "'". $this->other[$key]."'";
                    }else{
                        $meanInfo = "'". $this->mean[$key]."'";
                    }
                    if (is_array($this->mean[$key])){
                        $content[$meanInfo] =  $this->mean[$key][$this->pre[$key]].' -> '. $this->mean[$key][$val];
                    }else{
                        $content[$meanInfo] =  $this->pre[$key].' -> '. $this->next[$key];
                    }
                }
            }
        }
        $data = [
            'module' =>  $this->module->pid,
            'operate' =>  $this->module->id,
            'type' =>  $this->module->type,
            'main' =>  '图片',
            'main_id' => isset($this->pre['id']) ? $this->pre['id'] : 0,
            'content' => json_encode($content,JSON_UNESCAPED_UNICODE),
            'user_id' => auth('admin')->user()->id,
            'ip'    => get_proxy_ip(),
            'model' => $this->module->model,
        ];

        return $data;
    }
}
